﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace fabao.Common.Extensions.DependencyInjection
{
    public static class ServiceLocator
    {
        private static IServiceProvider? _provider;
        static ServiceLocator()
        {
        }
        /// <summary>
        /// 服务定位器，获取已注册的服务
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown if Provider is already set.</exception>
        /// <exception cref="ArgumentNullException">Thrown if value is null when setting Provider.</exception>
        public static IServiceProvider? Provider
        {
            get => _provider;
            set => _provider = _provider is not null ? throw new InvalidOperationException($"{nameof(Provider)} is already set.") : value ?? throw new ArgumentNullException(nameof(value));
        }
    }
}
